# Python 2.6.4
# Project Euler, Problem 119
# Copyright 2010 Talha Zaman

import psyco
psyco.full()

def dsum(n):
    ds = 0
    while n: ds, n = ds+n%10, n/10
    return ds

print sorted(i**j for i in range(70) for j in range(9) if i**j>9 and dsum(i**j)==i)[29]
